<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        *{
            margin: 0;
            padding: 0;
        }
        li{
            list-style-type: none;
            width: 666px;
            height: 30px;
            margin-bottom: 5px;
            background-color: antiquewhite;
        }
        .box{
            width: 777px;
            height: 500px;
            border: 1px solid;
            margin: auto;
        }
        .box1{
            width: 666px;
            height: 350px;
            border: 1px solid;
            margin: auto;
        }
        .ly{
            width: 666px;
            height: 50px;
            margin: auto;
            margin-top: 10px;
        }
        input{
            display: block;
            width: 666px;
            height: 50px;
        }
        .an{
            display: block;
            padding: 10px 20px;
            float:right;
            margin-top: 10px;
        }
        .sanc{
            float: right;
        }
    </style>
</head>
<body>
    <div class="box">
        <h3>留言板</h3>
        <div class="box1">
            <ul></ul>
        </div>
        <div class="box2">
            <div class="ly">
                <textarea placeholder="请输入内容"></textarea>
                <button class="an">发送</button>
            </div>
        </div>
    </div>
</body>
<script>
    var btn = document.querySelector('.an');
    var text=document.querySelector('textarea');
    var ul=document.querySelector('ul');
    btn.onclick = function() {
        if (text.value== '') { 
            alert('您没有输入内容'); 
            return false;
        }else {
            var li = document.createElement('li'); 
            li.innerHTML= text.value;
            var button = document.createElement('button'); 
            button.className = 'sanc';
            button.innerHTML ='删除';
            button.onclick = function () {
            ul.removeChild(this.parentNode);
        };
        li.appendChild (button);
            ul.insertBefore(li, ul.children[0]);
        }
    };
    
</script>
</body>
</html>